package de.muahd.saga.ui.jsf2.beans;

import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import de.muahd.saga.common.model.Customer;
import de.muahd.saga.services.core.api.CustomerService;

@Component
@Scope("prototype")
public class CustomerBean {
	
	@Autowired
	private CustomerService customerService;
	
	private String name;
	
	private List<Customer> customers;
	
	@PostConstruct
	public void init() {
		customers = customerService.findAll();
	}
	
	public String getName() {
		return "TODO - Replace me!";
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public List<Customer> getAllUsers() {
		return customers;
	}
	
	public void createRandomCustomer() {
		
		Customer customer = new Customer();
		customer.setFirstname("a");
		customer.setLastname("b");
		customerService.saveCustomer(customer);
	}
	
}
